home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / pctchnqs / 1992 / number1 / xkeytest.pas < prev   
Pascal/Delphi Source File  |  1992-01-20  |  4KB  |  106 lines

  1. PROGRAM XKeyTest;                           { Author: Ron Aaron }
  2. {===============================================================}
  3. { Tests the low-level keyboard handler provided by the ExtKey   }
  4. { unit.                                                         }
  5. { This program is hereby put in the public domain by its author.}
  6. {===============================================================}
  7. USES Crt, App, Objects, Views, Menus, Drivers, Extkey;
  8. CONST cmFilterKeys = 1000;  { Command to turn "duplicate" key...}
  9.                                        {...filtering on or off. }
  10. TYPE
  11. {---------------------------------------------------------------}
  12. { Make our new application type that understands extended kbd.  }
  13. {---------------------------------------------------------------}
  14.   TMyApplication = Object( TApplication )
  15.     CONSTRUCTOR Init;
  16.     PROCEDURE InitStatusLine; VIRTUAL;
  17.   END;
  18. {---------------------------------------------------------------}
  19. { Define a TWindow descendent for our test program's output.    }
  20. {---------------------------------------------------------------}
  21.   PMyWindow = ^TMyWindow;
  22.   TMyWindow = Object(TWindow)
  23.     PROCEDURE HandleEvent ( VAR Event : TEvent); VIRTUAL;
  24.   END;
  25.  
  26. VAR Win : PMyWindow;              { The instance for our window }
  27. {===============================================================}
  28. PROCEDURE TMyWindow.HandleEvent( VAR Event : TEvent );
  29. {---------------------------------------------------------------}
  30. { Display the type of keyboard and the keycodes for the         }
  31. { keyboard.  NOTE: Not all extended keys are shown.
  32. {---------------------------------------------------------------}
  33. VAR OutStr : STRING;
  34.     Extra  : STRING;
  35.     Parms  : ARRAY[0..0] OF LongInt;
  36. BEGIN
  37.   CASE Event.What OF
  38.     evKeyDown: BEGIN
  39.       Parms[0] := Event.keycode;
  40.       IF ExtKeyboardInstalled THEN BEGIN
  41.         Extra := '            ';
  42.         FormatStr(OutStr, 'ExtKey: %04X', Parms);
  43.         CASE Event.keycode OF
  44.           kbF12 : OutStr := OutStr +       ' -- F12!    ';
  45.           kbF11 : OutStr := OutStr +       ' -- F11!    ';
  46.           kbCtrlUp : OutStr := OutStr +    ' -- Ctrl+Up!';
  47.           kbPadCtrlUp : OutStr := OutStr + ' Ctrl+PadUp!';
  48.           kbAltUp : OutStr := OutStr +     ' -- Alt+Up! '
  49.           ELSE OutStr := OutStr + Extra;
  50.          END;
  51.         END
  52.       ELSE
  53.         FormatStr(OutStr, 'StdKey: %04X', Parms);
  54.       WriteStr(2,2,OutStr, 1);
  55.     END;
  56.     evCommand: BEGIN
  57.       IF Event.command = cmFilterKeys THEN
  58.         FilterDuplicateKeys := NOT FilterDuplicateKeys;
  59.     END;
  60.   END; {--------------------------------- CASE Event.What OF... }
  61. {---------------------------------------------------------------}
  62. { Let the standard Window handler do its thing.                 }
  63. {---------------------------------------------------------------}
  64.   TWindow.HandleEvent(Event);
  65. END;
  66. {===============================================================}
  67. CONSTRUCTOR TMyApplication.Init;
  68. {---------------------------------------------------------------}
  69. { Initialize the application by creating a fixed window that is }
  70. { slightly smaller than the DeskTop.                            }
  71. {---------------------------------------------------------------}
  72. VAR R : TRect;
  73. BEGIN
  74.   TApplication.Init;
  75.   Desktop^.GetBounds(R);
  76.   R.Grow(-4,-4);
  77.   Win := New(PMyWindow, Init(r, 'Key', 0));
  78.   Win^.Flags := 0;                  { Make this a static window }
  79.   Desktop^.Insert(Win);
  80. END;
  81. {===============================================================}
  82. PROCEDURE TMyApplication.InitStatusLine;
  83. {---------------------------------------------------------------}
  84. { Define a status line for the Desktop.                         }
  85. {---------------------------------------------------------------}
  86. VAR R : TRect;
  87. BEGIN
  88.   GetExtent(R);
  89.   R.A.Y := R.B.Y - 1;
  90.   StatusLine := New(PStatusLine,Init(R,
  91.                   NewStatusDef(0, $FFFF,
  92.                     NewStatusKey('~Alt-X~ Exit', kbAltX, cmQuit,
  93.                     NewStatusKey('~Shift-F12~ Filter', kbShiftF12,
  94.                                  cmFilterKeys,nil)),nil)));
  95. END;
  96. {===============================================================}
  97. {============== M A I N   P R O G R A M   L O G I C ============}
  98. {===============================================================}
  99. VAR MyApp : TMyApplication;
  100.     Event : TEvent;
  101. BEGIN
  102.   MyApp.Init;
  103.   MyApp.Run;
  104.   MyApp.Done;
  105. END.
  106.